package com.b2b.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Service
public class AsyncService {

    @Async("doSomethingExecutor")
    public CompletableFuture<String> doSomething1(String message) throws InterruptedException {
        Thread.sleep(1000);
        System.out.println(Thread.currentThread() + ("do something1: " + message));
        return CompletableFuture.completedFuture(Thread.currentThread() + ("do something1: " + message));
    }

    @Async("doSomethingExecutor")
    public CompletableFuture<String> doSomething2(String message) throws InterruptedException {
        Thread.sleep(1000);
        System.out.println(Thread.currentThread() + ("do something2: " + message));
        return CompletableFuture.completedFuture(Thread.currentThread() + "; do something2: " + message);
    }

    @Async("doSomethingExecutor")
    public CompletableFuture<String> doSomething3(String message) throws InterruptedException {
        Thread.sleep(1000);
        System.out.println(Thread.currentThread() + ("do something3: " + message));
        return CompletableFuture.completedFuture(Thread.currentThread() + "; do something3: " + message);
    }
}
